<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var message = 'my name is why'
    var name = 'why'
    /**
     * 搜素到了,返回索引位置
     * 没有搜索到,返回-1
    */
    console.log(message.indexOf('why')) // 11
    console.log(message.indexOf('qq'))  // -1
    if (message.indexOf(name) !== -1) {
      console.log("message中包含name")
    } else {
      console.log("message不包含name")
    }

    // ES6中新增方法
    // 判断包含关系
    if (message.includes(name)) {
      console.log("message中包含name")
    } else {
      console.log("message不包含name")
    }

    console.log(message.startsWith("kobe")) // false
    console.log(message.endsWith("why")) // true

    // 替换字符串
    console.log(message.replace("why", "kobe"))

    console.log(message.replace("why", function () {
      return "kobe"
    }))


  </script>
</body>

</html>